#include "Enemy.hh"

Enemy::Enemy(const std::string& name, unsigned health, unsigned defense, unsigned attack)
    : name(name), health(health), attackPower(attack), defensePower(defense){}

std::string Enemy::getName() const {
    return name;
}
    
unsigned Enemy::getHealth() const {
    return health;
}
    
unsigned Enemy::getAttack() const {
    return attackPower;
}

unsigned Enemy::getDefense() const {
    return defensePower;
}
    
std::string Enemy::toString() const {
    return name + " [HP: " + std::to_string(health) + ", attackPower: " + std::to_string(attackPower) + ", defencesPower: "+ std::to_string(defensePower)+ "]";
}
    
bool Enemy::isAlive() const {
    return health > 0;
}
    
void Enemy::attack(ICharacter& target) {
    unsigned attackpoint;
    if (attackPower >= target.getDefense()/2){
        attackpoint = attackPower - target.getDefense()/2;
    }else{
        attackpoint = 0;
    }
    std::cout << name << " attacks " << target.getName() << " causes " << attackpoint << " damage!\n";
    target -= attackpoint;
}
    
ICharacter& Enemy::operator-=(unsigned damage) {
    if (damage >= health) {
        health = 0;
    } else {
        health -= damage;
    }
    std::cout << name << " receives " << damage << " damage. Current HP: " << health << "\n";
    return *this;
}

ICharacter& Enemy::operator*(ICharacter& target) {
    return *this;
}
